package com.addressbook.tests;

import org.testng.annotations.Test;

import com.addressbook.fw.Folders;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;;

public class FolderCreationTest extends TestBase {
	@Test
	public void testNewFolderCreation() {
		String folder = "test-folder" + generationRandomString();
		Folders oldFolders = app.getFolderHelper().getFolders();
		app.getFolderHelper().createFolder(folder);
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder)));
	}

	@Test
	public void testVariosFoldersCreation() {
		String folder1 = "test-folder" + generationRandomString();
		String folder2 = "test-folder" + generationRandomString();

		Folders oldFolders1 = app.getFolderHelper().getFolders();

		assertThat(app.getFolderHelper().createFolder(folder1), is(nullValue()));
		Folders newFolders1 = app.getFolderHelper().getFolders();
		assertThat(newFolders1, equalTo(oldFolders1.withAdded(folder1)));

		Folders oldFolders2 = app.getFolderHelper().getFolders();

		assertThat(app.getFolderHelper().createFolder(folder2), is(nullValue()));
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2, equalTo(oldFolders2.withAdded(folder2)));
	}

	@Test
	public void testWithSameFoldersCreation() {
		String folder = "test-folder" + generationRandomString();

		Folders oldFolders1 = app.getFolderHelper().getFolders();

		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));
		Folders newFolders1 = app.getFolderHelper().getFolders();
		assertThat(newFolders1, equalTo(oldFolders1.withAdded(folder)));

		Folders oldFolders2 = app.getFolderHelper().getFolders();

		assertThat(app.getFolderHelper().createFolder(folder),
				containsString("Duplicated folder name"));
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2, equalTo(oldFolders2));
	}
}